<template>
  <h1>员工列表练习</h1>
  <el-form style="width: 600px;margin: 0 auto;" label-width="80">
    <el-form-item label="姓名">
      <el-input type="text" placeholder="请输入员工姓名" v-model="emp.name"></el-input>
    </el-form-item>
    <el-form-item label="工资">
      <el-input type="text" placeholder="请输入员工工资" v-model="emp.salary"></el-input>
    </el-form-item>
    <el-form-item label="岗位">
      <el-input type="text" placeholder="请输入员工岗位" v-model="emp.job"></el-input>
    </el-form-item>
    <el-form-item>
      <el-button type="success" @click="add">点我提交</el-button>
    </el-form-item>
  </el-form>
  <el-table :data="arr" style="width: 600px;margin: 0 auto;">
    <el-table-column label="编号" type="index" width="80" align="center"></el-table-column>
    <el-table-column label="姓名" prop="name" align="center"></el-table-column>
    <el-table-column label="工资" prop="salary" align="center"></el-table-column>
    <el-table-column label="岗位" prop="job" align="center"></el-table-column>
    <el-table-column label="操作" align="center">
      <template #default="scope">
        <el-button type="danger" @click="del(scope.row,scope.$index)">删除</el-button>
      </template>
    </el-table-column>
  </el-table>
</template>

<script setup>
import {ref} from "vue";
import {ElMessage} from "element-plus";

const arr = ref([])
const emp = ref({
  name: '',
  salary: '',
  job: ''
})
const add = () => {
  if (emp.value.name || emp.value.salary || emp.value.job) {
    arr.value.push(emp.value)
  }
  else {
    ElMessage.error('请输入完整信息');
    return;
  }
}
const del = (item, index) => {
  if (confirm('确认删除' + item.name + '吗？')) {
    arr.value.splice(index, 1)
  }
}
</script>

<style scoped>

</style>